package com.youmu.sichuansfc.controller.manager;

import com.youmu.sichuansfc.common.CommonRes;
import com.youmu.sichuansfc.service.CompanyService;
import com.youmu.sichuansfc.util.ReadEXCEL;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author WYZ
 * @create 2018-02-27 11:03
 * @desc
 **/
@Controller
public class CompanyMangerController {

    @Autowired
    CompanyService companyService;
    private Logger logger = Logger.getLogger(this.getClass());
    /**
     *  统计 每个地区公司的类型数量
     * @return
     */
    @RequestMapping(value = "/company/type/statistic", method =  RequestMethod.GET)
    public @ResponseBody
    CommonRes CompanyTypestatistic(@RequestParam(name = "areaId", required =  false) Long areaId,
                                   @RequestParam(name = "type", required =  false) int type){
        try {
             return CommonRes.success(companyService.CompanyTypestatistic(type,areaId));
        }catch (Exception e){
            e.printStackTrace();
        }
        return  CommonRes.fail();
    }

    /**
     *  统计 地域统计
     */
    @RequestMapping(value = "/company/area/statistic", method =  RequestMethod.GET)
    public @ResponseBody
    CommonRes CompanyTypestatistic(@RequestParam(name = "areaId", required =  false) Long areaId){

        try {
            return CommonRes.success(companyService.CompanyAreaStatistic(areaId));
        }catch (Exception e){
            e.printStackTrace();
        }
        return  CommonRes.fail();
    }

    @RequestMapping(value = "/company/type/excel", method =  RequestMethod.GET)
    public @ResponseBody
    CommonRes CompanyTypestatisticExcel(@RequestParam(name = "areaId", required =  false) Long areaId,
                                        @RequestParam(name = "type", required =  false) int type,
                                        HttpServletRequest httpServletRequest,
                                        HttpServletResponse httpServletResponse){
        try {
            String excelPath = new ReadEXCEL().exportManagerTypeExcel(httpServletRequest,httpServletResponse,companyService.CompanyTypestatistic(type,areaId));
            return CommonRes.success();
        }catch (Exception e){
            e.printStackTrace();
        }
        return  CommonRes.fail();
    }
}
